﻿package com.efg.games.superclick
{
    // Import necessary classes from the flash libraries
    import flash.display.Graphics;
    import flash.display.LineScaleMode;
    import flash.display.Shape;
    import flash.display.Sprite
    import flash.events.MouseEvent;
    import flash.text.TextField;
    import flash.text.TextFormat;
    
    /**
     * ...
     * @author Jeff Fulton
     */
    public class Circle extends Sprite implements IDispose, IUpdate
    {
        //Constsants used to define circle type
        static public const CIRCLE_GOOD:int = 0;
        static public const CIRCLE_BAD:int = 1;
        
        static public const GOOD_COLOR:uint = 0x0000FF;
        static public const BAD_COLOR:uint = 0xFF0000;
        
        public var type:int;
        public var clicked:Boolean = false;
        public var fadingOut:Boolean = false;
        
        private var _growSpeed:Number;
         
        //Constructor sets the handcursor mode and accepts type constant
        //init is called and type is passed to it
        
        public function Circle(typeval:int,growSpeed:Number)
        {
            buttonMode = true;
            useHandCursor = true;
            _growSpeed = growSpeed;
            init(typeval);
        }
        
        //init
        //1. Based on the typeval passed, sets the type attribute
        //2. Based on type, sets the color of the cirle
        private function init(typeval:int):void
        {
            var shapeColor:Number;
            switch (typeval)
            {
                case CIRCLE_GOOD: 
                    //good circle
                    shapeColor = GOOD_COLOR;
                    type = typeval;
                    break;
                case CIRCLE_BAD: 
                    //bad circle
                    shapeColor = BAD_COLOR;
                    type = typeval;
                    break;
            
            }
            
            var g:Graphics = this.graphics;
            g.clear();
            g.lineStyle(2, 0xffffff, 1, false, LineScaleMode.NONE);
            g.beginFill(shapeColor);
            g.drawCircle(5, 5, 8);
            g.endFill();
            
            scaleX = .5;
            scaleY = .5;
        }
        
        public function update():void
        {
            if (fadingOut)
            {
                alpha -= .05;
            }
            else
            {
                scaleX += _growSpeed;
                scaleY += _growSpeed;
            }
        }
        
        //Dispose is needed to get rid of unwanted objects and get them ready for garbage collection
        public function dispose():void
        {
            var g:Graphics = this.graphics;
            g.clear();
            g = null;
        }
        
        public function isDispose():Boolean 
        {
            if (this.alpha < 0)
            {
                return true;
            }
            return false;
        }
    
    }

}